package com.example.comtest;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

import android.app.Dialog;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

public class Connection extends Thread {

	
	private int port = 7890;
	private String hostname = "194.47.41.112";
	private Socket socket;
	private BufferedReader in;
	private PrintWriter out;
	private String clientMsg;
	
	public Connection(String msg) {
		clientMsg = msg;

	}

	public void run() {
		
		try {
			socket = new Socket(hostname, port);
			out = new PrintWriter(socket.getOutputStream(),true);
			in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
				
			Log.i("msg", "sending msg");
			out.println(clientMsg);
			Log.i("msg", "sent msg");
			
			String msgFromServer = in.readLine();
			Log.i("msg", "server said " + msgFromServer);
			
			out.close();
			in.close();
			socket.close();
		} catch (Exception e) {
			Log.i("ERROR","Eror: " + e);
		}
		
	}
}
